/*********************************** (C) COPYRIGHT ******************************
 * address: https://gitee.com/liuniansihuo/multitasks-os
 *
 * Change Logs:
 * Date			Author      	Notes
 * 2018-11-21	LiuHuo			first version
 *
*******************************************************************************/
#ifndef _QueueRing_H_
#define _QueueRing_H_


struct QueRing_s
{
	unsigned short head;//以队列入口为头
	unsigned short tail;//以队列出口为尾
	unsigned short size;//队列元素个数
	unsigned short type;//元素大小，元素可以时任意类型数据
	void *buff;//队列缓存，缓存所占用大小=size*type
};


 unsigned short SetTail(struct QueRing_s* Q, unsigned short offset);
 unsigned short SetHeadOffset(struct QueRing_s *Q,unsigned short offset);
 unsigned short  SetHead(struct QueRing_s *Q,unsigned short  head);
 void * GetData(struct QueRing_s*Q,unsigned short offset);
 void * GetDataAdd(struct QueRing_s*Q);
 unsigned short SetData(struct QueRing_s*Q,void* data,unsigned short len);
 void QueueInit(struct QueRing_s * Q, void * buff, unsigned short size,unsigned short type);


//zhe minimizing set
#define QGetSize(Q)			((Q)->size)
#define QGetHead(Q)			((Q)->head)
#define QGetTail(Q)			((Q)->tail)
#define QGetType(Q)			((Q)->type)

/******************************************************/
/***************对任何队列的操作，只使用如下的宏定义********************/
/******************************************************/

//队列是否为空
#define QEmpty(Q)			(QGetHead(Q) == QGetTail(Q))
//队列当前元素个数
#define QCurrentSize(Q)		((QGetSize(Q)+QGetHead(Q)-QGetTail(Q))%QGetSize(Q))
//队列当前空闲个数
#define QRemainSize(Q)		(QGetSize(Q)-QCurrentSize(Q)-1)
//设置队尾偏移
#define QSetTail(Q,x)		SetTail((Q),x)
//设置队头偏移
#define QSetHeadOffset(Q,x)	SetHeadOffset((Q),x)
//设置队头
#define QSetHead(Q,x)		SetHead((Q),x)
//获取队尾偏移元素
#define QGetData(Q,x)		GetData(Q,x)
//获取元素
#define QGetDataAdd(Q)		GetDataAdd((Q))
//插入元素
#define QSetData(Q,x,y)		SetData((Q),x,y)
//空队列初始化
#define QQueueInit(Q,buff,size,type) QueueInit((Q),buff,size,type)


#endif




